\hypertarget{utils_8c}{}\section{utils.\+c File Reference}
\label{utils_8c}\index{utils.\+c@{utils.\+c}}
{\ttfamily \#include \char`\"{}utils.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}ch.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}hal.\+h\char`\"{}}\\*
{\ttfamily \#include $<$math.\+h$>$}\\*
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \hyperlink{utils_8c_a0c9b64b7b3425454abf96dd55a70e987}{utils\+\_\+step\+\_\+towards} (float $\ast$value, float goal, float step)
\item 
float \hyperlink{utils_8c_a5beb0994a105ec3bb655c776640600cf}{utils\+\_\+calc\+\_\+ratio} (float low, float high, float val)
\item 
void \hyperlink{utils_8c_aa3e84469a5fae04219c3dc8462d1c232}{utils\+\_\+norm\+\_\+angle} (float $\ast$angle)
\item 
int \hyperlink{utils_8c_add1a8dc5994422e397107bd390656292}{utils\+\_\+truncate\+\_\+number} (float $\ast$number, float min, float max)
\item 
float \hyperlink{utils_8c_a65c32996543b3f6afe56c241354090bf}{utils\+\_\+map} (float x, float in\+\_\+min, float in\+\_\+max, float out\+\_\+min, float out\+\_\+max)
\item 
int \hyperlink{utils_8c_aa66d6805c1cb72df13d5120582da7a20}{utils\+\_\+map\+\_\+int} (int x, int in\+\_\+min, int in\+\_\+max, int out\+\_\+min, int out\+\_\+max)
\item 
void \hyperlink{utils_8c_a3f53ff1f6bd8ad3a7f0abe93e421fa82}{utils\+\_\+deadband} (float $\ast$value, float tres, float max)
\item 
float \hyperlink{utils_8c_ac5f9ac4df6fe707e1d2559fd8c6238f7}{utils\+\_\+angle\+\_\+difference} (float angle1, float angle2)
\item 
float \hyperlink{utils_8c_a7d2432044cfcaa7310bdd7c50fde7ceb}{utils\+\_\+middle\+\_\+of\+\_\+3} (float a, float b, float c)
\item 
int \hyperlink{utils_8c_a6a0e040caf33f3a46df39abdb981b495}{utils\+\_\+middle\+\_\+of\+\_\+3\+\_\+int} (int a, int b, int c)
\item 
void \hyperlink{utils_8c_a34445d4a30d2870aa3bfffe403e2d4fe}{utils\+\_\+sys\+\_\+lock\+\_\+cnt} (void)
\item 
void \hyperlink{utils_8c_aa9de4981bd427c34252ca520ac974e64}{utils\+\_\+sys\+\_\+unlock\+\_\+cnt} (void)
\end{DoxyCompactItemize}


\subsection{Function Documentation}
\hypertarget{utils_8c_ac5f9ac4df6fe707e1d2559fd8c6238f7}{}\index{utils.\+c@{utils.\+c}!utils\+\_\+angle\+\_\+difference@{utils\+\_\+angle\+\_\+difference}}
\index{utils\+\_\+angle\+\_\+difference@{utils\+\_\+angle\+\_\+difference}!utils.\+c@{utils.\+c}}
\subsubsection[{utils\+\_\+angle\+\_\+difference(float angle1, float angle2)}]{\setlength{\rightskip}{0pt plus 5cm}float utils\+\_\+angle\+\_\+difference (
\begin{DoxyParamCaption}
\item[{float}]{angle1, }
\item[{float}]{angle2}
\end{DoxyParamCaption}
)}\label{utils_8c_ac5f9ac4df6fe707e1d2559fd8c6238f7}
Get the difference between two angles. Will always be between -\/180 and +180 degrees. 
\begin{DoxyParams}{Parameters}
{\em angle1} & The first angle \\
\hline
{\em angle2} & The second angle \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The difference between the angles 
\end{DoxyReturn}
\hypertarget{utils_8c_a5beb0994a105ec3bb655c776640600cf}{}\index{utils.\+c@{utils.\+c}!utils\+\_\+calc\+\_\+ratio@{utils\+\_\+calc\+\_\+ratio}}
\index{utils\+\_\+calc\+\_\+ratio@{utils\+\_\+calc\+\_\+ratio}!utils.\+c@{utils.\+c}}
\subsubsection[{utils\+\_\+calc\+\_\+ratio(float low, float high, float val)}]{\setlength{\rightskip}{0pt plus 5cm}float utils\+\_\+calc\+\_\+ratio (
\begin{DoxyParamCaption}
\item[{float}]{low, }
\item[{float}]{high, }
\item[{float}]{val}
\end{DoxyParamCaption}
)}\label{utils_8c_a5beb0994a105ec3bb655c776640600cf}
\hypertarget{utils_8c_a3f53ff1f6bd8ad3a7f0abe93e421fa82}{}\index{utils.\+c@{utils.\+c}!utils\+\_\+deadband@{utils\+\_\+deadband}}
\index{utils\+\_\+deadband@{utils\+\_\+deadband}!utils.\+c@{utils.\+c}}
\subsubsection[{utils\+\_\+deadband(float $\ast$value, float tres, float max)}]{\setlength{\rightskip}{0pt plus 5cm}void utils\+\_\+deadband (
\begin{DoxyParamCaption}
\item[{float $\ast$}]{value, }
\item[{float}]{tres, }
\item[{float}]{max}
\end{DoxyParamCaption}
)}\label{utils_8c_a3f53ff1f6bd8ad3a7f0abe93e421fa82}
Truncate absolute values less than tres to zero. The value tres will be mapped to 0 and the value max to max. \hypertarget{utils_8c_a65c32996543b3f6afe56c241354090bf}{}\index{utils.\+c@{utils.\+c}!utils\+\_\+map@{utils\+\_\+map}}
\index{utils\+\_\+map@{utils\+\_\+map}!utils.\+c@{utils.\+c}}
\subsubsection[{utils\+\_\+map(float x, float in\+\_\+min, float in\+\_\+max, float out\+\_\+min, float out\+\_\+max)}]{\setlength{\rightskip}{0pt plus 5cm}float utils\+\_\+map (
\begin{DoxyParamCaption}
\item[{float}]{x, }
\item[{float}]{in\+\_\+min, }
\item[{float}]{in\+\_\+max, }
\item[{float}]{out\+\_\+min, }
\item[{float}]{out\+\_\+max}
\end{DoxyParamCaption}
)}\label{utils_8c_a65c32996543b3f6afe56c241354090bf}
\hypertarget{utils_8c_aa66d6805c1cb72df13d5120582da7a20}{}\index{utils.\+c@{utils.\+c}!utils\+\_\+map\+\_\+int@{utils\+\_\+map\+\_\+int}}
\index{utils\+\_\+map\+\_\+int@{utils\+\_\+map\+\_\+int}!utils.\+c@{utils.\+c}}
\subsubsection[{utils\+\_\+map\+\_\+int(int x, int in\+\_\+min, int in\+\_\+max, int out\+\_\+min, int out\+\_\+max)}]{\setlength{\rightskip}{0pt plus 5cm}int utils\+\_\+map\+\_\+int (
\begin{DoxyParamCaption}
\item[{int}]{x, }
\item[{int}]{in\+\_\+min, }
\item[{int}]{in\+\_\+max, }
\item[{int}]{out\+\_\+min, }
\item[{int}]{out\+\_\+max}
\end{DoxyParamCaption}
)}\label{utils_8c_aa66d6805c1cb72df13d5120582da7a20}
\hypertarget{utils_8c_a7d2432044cfcaa7310bdd7c50fde7ceb}{}\index{utils.\+c@{utils.\+c}!utils\+\_\+middle\+\_\+of\+\_\+3@{utils\+\_\+middle\+\_\+of\+\_\+3}}
\index{utils\+\_\+middle\+\_\+of\+\_\+3@{utils\+\_\+middle\+\_\+of\+\_\+3}!utils.\+c@{utils.\+c}}
\subsubsection[{utils\+\_\+middle\+\_\+of\+\_\+3(float a, float b, float c)}]{\setlength{\rightskip}{0pt plus 5cm}float utils\+\_\+middle\+\_\+of\+\_\+3 (
\begin{DoxyParamCaption}
\item[{float}]{a, }
\item[{float}]{b, }
\item[{float}]{c}
\end{DoxyParamCaption}
)}\label{utils_8c_a7d2432044cfcaa7310bdd7c50fde7ceb}
Get the middle value of three values


\begin{DoxyParams}{Parameters}
{\em a} & First value\\
\hline
{\em b} & Second value\\
\hline
{\em c} & Third value\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The middle value 
\end{DoxyReturn}
\hypertarget{utils_8c_a6a0e040caf33f3a46df39abdb981b495}{}\index{utils.\+c@{utils.\+c}!utils\+\_\+middle\+\_\+of\+\_\+3\+\_\+int@{utils\+\_\+middle\+\_\+of\+\_\+3\+\_\+int}}
\index{utils\+\_\+middle\+\_\+of\+\_\+3\+\_\+int@{utils\+\_\+middle\+\_\+of\+\_\+3\+\_\+int}!utils.\+c@{utils.\+c}}
\subsubsection[{utils\+\_\+middle\+\_\+of\+\_\+3\+\_\+int(int a, int b, int c)}]{\setlength{\rightskip}{0pt plus 5cm}int utils\+\_\+middle\+\_\+of\+\_\+3\+\_\+int (
\begin{DoxyParamCaption}
\item[{int}]{a, }
\item[{int}]{b, }
\item[{int}]{c}
\end{DoxyParamCaption}
)}\label{utils_8c_a6a0e040caf33f3a46df39abdb981b495}
Get the middle value of three values


\begin{DoxyParams}{Parameters}
{\em a} & First value\\
\hline
{\em b} & Second value\\
\hline
{\em c} & Third value\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The middle value 
\end{DoxyReturn}
\hypertarget{utils_8c_aa3e84469a5fae04219c3dc8462d1c232}{}\index{utils.\+c@{utils.\+c}!utils\+\_\+norm\+\_\+angle@{utils\+\_\+norm\+\_\+angle}}
\index{utils\+\_\+norm\+\_\+angle@{utils\+\_\+norm\+\_\+angle}!utils.\+c@{utils.\+c}}
\subsubsection[{utils\+\_\+norm\+\_\+angle(float $\ast$angle)}]{\setlength{\rightskip}{0pt plus 5cm}void utils\+\_\+norm\+\_\+angle (
\begin{DoxyParamCaption}
\item[{float $\ast$}]{angle}
\end{DoxyParamCaption}
)}\label{utils_8c_aa3e84469a5fae04219c3dc8462d1c232}
Make sure that 0 $<$= angle $<$ 360 
\begin{DoxyParams}{Parameters}
{\em angle} & The angle to normalize. \\
\hline
\end{DoxyParams}
\hypertarget{utils_8c_a0c9b64b7b3425454abf96dd55a70e987}{}\index{utils.\+c@{utils.\+c}!utils\+\_\+step\+\_\+towards@{utils\+\_\+step\+\_\+towards}}
\index{utils\+\_\+step\+\_\+towards@{utils\+\_\+step\+\_\+towards}!utils.\+c@{utils.\+c}}
\subsubsection[{utils\+\_\+step\+\_\+towards(float $\ast$value, float goal, float step)}]{\setlength{\rightskip}{0pt plus 5cm}void utils\+\_\+step\+\_\+towards (
\begin{DoxyParamCaption}
\item[{float $\ast$}]{value, }
\item[{float}]{goal, }
\item[{float}]{step}
\end{DoxyParamCaption}
)}\label{utils_8c_a0c9b64b7b3425454abf96dd55a70e987}
\hypertarget{utils_8c_a34445d4a30d2870aa3bfffe403e2d4fe}{}\index{utils.\+c@{utils.\+c}!utils\+\_\+sys\+\_\+lock\+\_\+cnt@{utils\+\_\+sys\+\_\+lock\+\_\+cnt}}
\index{utils\+\_\+sys\+\_\+lock\+\_\+cnt@{utils\+\_\+sys\+\_\+lock\+\_\+cnt}!utils.\+c@{utils.\+c}}
\subsubsection[{utils\+\_\+sys\+\_\+lock\+\_\+cnt(void)}]{\setlength{\rightskip}{0pt plus 5cm}void utils\+\_\+sys\+\_\+lock\+\_\+cnt (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}\label{utils_8c_a34445d4a30d2870aa3bfffe403e2d4fe}
A system locking function with a counter. For every lock, a corresponding unlock must exist to unlock the system. That means, if lock is called five times, unlock has to be called five times as well. Note that ch\+Sys\+Lock and ch\+Sys\+Lock\+From\+Isr are the same for this port. \hypertarget{utils_8c_aa9de4981bd427c34252ca520ac974e64}{}\index{utils.\+c@{utils.\+c}!utils\+\_\+sys\+\_\+unlock\+\_\+cnt@{utils\+\_\+sys\+\_\+unlock\+\_\+cnt}}
\index{utils\+\_\+sys\+\_\+unlock\+\_\+cnt@{utils\+\_\+sys\+\_\+unlock\+\_\+cnt}!utils.\+c@{utils.\+c}}
\subsubsection[{utils\+\_\+sys\+\_\+unlock\+\_\+cnt(void)}]{\setlength{\rightskip}{0pt plus 5cm}void utils\+\_\+sys\+\_\+unlock\+\_\+cnt (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}\label{utils_8c_aa9de4981bd427c34252ca520ac974e64}
A system unlocking function with a counter. For every lock, a corresponding unlock must exist to unlock the system. That means, if lock is called five times, unlock has to be called five times as well. Note that ch\+Sys\+Unlock and ch\+Sys\+Unlock\+From\+Isr are the same for this port. \hypertarget{utils_8c_add1a8dc5994422e397107bd390656292}{}\index{utils.\+c@{utils.\+c}!utils\+\_\+truncate\+\_\+number@{utils\+\_\+truncate\+\_\+number}}
\index{utils\+\_\+truncate\+\_\+number@{utils\+\_\+truncate\+\_\+number}!utils.\+c@{utils.\+c}}
\subsubsection[{utils\+\_\+truncate\+\_\+number(float $\ast$number, float min, float max)}]{\setlength{\rightskip}{0pt plus 5cm}int utils\+\_\+truncate\+\_\+number (
\begin{DoxyParamCaption}
\item[{float $\ast$}]{number, }
\item[{float}]{min, }
\item[{float}]{max}
\end{DoxyParamCaption}
)}\label{utils_8c_add1a8dc5994422e397107bd390656292}
